<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8" />
    <title>公众号信息表</title>
    <script src="/static/skin.js"></script>
	<link rel="stylesheet" href="/static/basic/plugins/easyui/themes/icon.css" >
	<link rel="stylesheet" type="text/css" href="/static/m.css?v=1227" >
	<script src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js"></script>
	<script src="/static/basic/plugins/easyui/jquery.easyui.min.js"></script>
	<script src="/static/init.js"></script>
	<script src="/static/searchEdit.js?v=0130"></script>
	<script src="/static/basic/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
	<script src="https://cdn.staticfile.org/moment.js/2.24.0/moment.min.js"></script>
</head>
<body>
<div class="easyui-layout" data-options="fit:true"  >
	<div data-options="region:'center'" >
		<table id="gridList" ></table>
	</div>
	<div data-options="region:'north'" >
			<a href="javascript:void(0)" id="addButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">新增</a>
			<a href="javascript:void(0)" id="editButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'">编辑</a>
			<a href="javascript:void(0)" id="removeButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'">删除</a>
			<a href="javascript:void(0)" id="btn3" class="easyui-linkbutton c6" data-options="plain:true">修改欢迎信息</a>
			<a href="javascript:void(0)" id="btn2" class="easyui-linkbutton" data-options="plain:true">同步所有用户数据</a>
	</div>
</div>
<div id="searchbar" style="padding:2px 5px;">
<form id="searchForm" >
	<a id="searchButton" href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'" >查询</a>
</form>
</div>
<script>
var options={
		page_id:77,
		grid_id:"gridList",
		sqlname:"grid_77_wx_account",
		column_formatter:{
			welcome_msg:function(value,row,index){
				//return value;
				return "<pre style='overflow:hidden'>"+value+"</pre>";
			},
			
		},
	};
	//document ready
	$(function(){
		grid1=new uniontrip.datagrid.searchEdit(options);
		
		$('#searchButton').bind('click',grid1.load);//查询操作绑定事件
		$('#addButton').bind('click', addRow);//新增行绑定事件
		$('#editButton').bind('click',grid1.editRow);//编辑按钮绑定事件
		$('#removeButton').bind('click',grid1.remove);//删除行绑定事件
		$('#saveButton').bind('click', grid1.accept);//保存datagrid绑定事件
		$('#cancelEditButton').bind('click',grid1.cancelEditing);//取消行编辑绑定事件
		$('#endEditingButton').bind('click', grid1.endEditing);//结束行编辑绑定事件
		$('#rejectButton').bind('click', grid1.rejectChanges);//撤销编辑绑定事件		
	    $('#showChangesButton').bind('click',grid1.showChanges);//信息变更提示
	    //初始化搜索框
	    initsearch();
	    $('#btn2').bind('click',syncuser);
	    $('#btn3').bind('click',function(){
			gridSelectRow(grid1.grid,function(row){
				editRow=row;
				EditDialogModifyMchId.dialog('open');
			});
		});
	    EditDialogModifyMchId=$("<div/>").appendTo("body").dialog({
			title:"修改欢迎信息",
			cls:"m-dialog",
			width:'400px',
			height:windowHeight*0.8,
			href:'modifyWelcomeMsg.html',
			modal:true,
			closed:true,
			//maximized:true,
			onClose:function(){
				console.log('onClose');
				
			},
			onBeforeClose:function(){//
				console.log('onBeforeClose');
				$("#modifyMchId-form").form('clear');
				//$("#smartwizard").data("smartWizard").options.anchorSettings.enableAllAnchors=false;
				//$('#smartwizard').smartWizard('reset');
			},
			 buttons: [{
				text:'保存',
				iconCls:'fas fa-save mbutton',
				handler:saveWelcomeMsg
			},{
				text:'取消',
				iconCls:'fas fa-times mbutton',
				handler:function(){
					EditDialogModifyMchId.dialog('close')
				}
			}],
			onBeforeOpen:function(){
				console.log('onBeforeOpen');
				if($(this).data("panel").isLoaded){
					
				}
			},
			onOpened:function(){
				console.log('onOpened');
				if(editRow){
		    		
					$("#modifyMchId-form").form('load',editRow);
		  			
				}else{
				}
				
			},
			onOpen:function(){//在onLoad之前执行
				console.log('onOpen');
				console.log($(this).panel('options'));
				//console.log();
				if($(this).data("panel").isLoaded){
					$(this).panel('options').onOpened();
				}
			},
			onBeforeLoad:function(){
				console.log('onBeforeLoad');
			},
			onLoad:function(){//只加载一次
				console.log('onLoad');
				//document.getElementById("id").fireEvent("click");
				$(this).panel('options').onOpened();
				//$('#lng').iCheck();
			},
		});
	});

	function saveWelcomeMsg(){
		if($("#modifyMchId-form").form('enableValidation').form('validate')){
			let data=$("#modifyMchId-form").serializeObject();
			data.appid=editRow.appid;
			$.post("/authenticated/wxapp/updateWelcomeMsg",data,function(result){
				if(result.success){
					info( "保存成功！");
					EditDialogModifyMchId.dialog('close');
					grid1.load();
				}else{
					$.messager.alert("提示", "保存失败！<br>"+result.message);
				}
			});
		}
	}
	/**
	 * 新增一行
	 */
	function addRow(){
		var newRowData={id:guid(),creator_id:sessionuser.id,creator_name:sessionuser.nickname,create_time:moment().format('YYYY-MM-DD')};//初始化行数据
		grid1.grid.datagrid('append',newRowData);	
	}
	function syncuser(){
		let row=grid1.getSelectedRow();
		if(row){
			$.messager.progress({interval:1000});
			$.post("/authenticated/wxuser/synchronize",{appid:row.appid},function(result){
				$.messager.progress('close');
				if(result.success){
					grid1.load();
					$.messager.alert("提示", "同步信息成功！");
				}else{
					$.messager.alert("提示", "同步信息失败！<br>"+result.message);
				}
			});
		}
		
	}
	/**
	 * 初始化搜索条件
	 */
	function initsearch(){
		/*$('#search-product_class_id').combotree({
			icons: [{
				iconCls:'icon-clear',
				handler:function(){
					$('#search-product_class_id').combotree('clear');
				}
			}],
		    data:grid1.combotreeDatas.product_class_id
		});
		//初始化combobox例子
		$('#search-status').combobox({
			panelHeight:'auto',
			editable:false,
			valueField:'code_value',
			textField:'code_name',
			icons: [{
				iconCls:'icon-clear',
				handler:function(){
					$('#search-status').combobox('clear');
				}
			}],
		    data:grid1.comboboxDatas.status
		});*/
	}
</script>
</body>
</html>